# Definition for a binary tree node.
class TreeNode:
  def __init__(self, x):
    self.val = x
    self.left = None
    self.right = None


# 重点在于：要直接判断当前值是否满足条件，而不是到了下一个节点才进行判断
# 这样就免去了进行重复的判断，出现WA
class Solution:
  def pathSum(self, root: TreeNode, sum: int) -> list:
    res = []
    if not root:
      return []
    def dfs(node: TreeNode, cur_sum: int, cur_path: list):
      if not node: return
      cur_path.append(node.val)
      if cur_sum + node.val == sum and not node.left and not node.right:
        res.append(cur_path[:])
      dfs(node.left, cur_sum + node.val, cur_path[:])
      dfs(node.right, cur_sum + node.val, cur_path[:])
    dfs(node=root, cur_sum=0, cur_path=[])
    return res


def stringToTreeNode(input):
  input = input.strip()
  input = input[1:-1]
  if not input:
    return None

  inputValues = [s.strip() for s in input.split(',')]
  root = TreeNode(int(inputValues[0]))
  nodeQueue = [root]
  front = 0
  index = 1
  while index < len(inputValues):
    node = nodeQueue[front]
    front = front + 1

    item = inputValues[index]
    index = index + 1
    if item != "null":
      leftNumber = int(item)
      node.left = TreeNode(leftNumber)
      nodeQueue.append(node.left)

    if index >= len(inputValues):
      break

    item = inputValues[index]
    index = index + 1
    if item != "null":
      rightNumber = int(item)
      node.right = TreeNode(rightNumber)
      nodeQueue.append(node.right)
  return root


def integerListToString(nums, len_of_list=None):
  import json
  if not len_of_list:
    len_of_list = len(nums)
  return json.dumps(nums[:len_of_list])


def main():
  import sys
  import io

  line_arr = input()
  line_sum = int(input())
  try:
    root = stringToTreeNode(line_arr)
    ret = Solution().pathSum(root, line_sum)
    out = integerListToString(ret)
    print(out)
  except StopIteration:
    exit(0)


'''
STATUS: LEARNT
TRIES:  N/A
TIME:   60 MS
MEMORY: 19.6 MB
'''
if __name__ == '__main__':
  main()
